<?php
function random_dates() {
    $dates_array = array();
    for($i = 0; $i < 5; $i++) {
        do {
            $rand = mt_rand(strtotime("now"),strtotime("+2 week"));
            $date = date("Y-m-d", $rand);
            $new_date = new DateTime($date);
            $random_hour = mt_rand(9, 16);
            $random_time = mt_rand(0, 1);
            if($random_time == 1) {
                $new_date->add(new DateInterval('PT'.$random_hour.'H30M'));
            }
            else {
                $new_date->add(new DateInterval('PT'.$random_hour.'H00M'));
            }
            $d = $new_date->format('Y-m-d H:i:s') . "";
        } while (in_array($d, $dates_array) && !in_array($onbeschikbaar));
        array_push($dates_array, $d);
    }
    return $dates_array;
}
?>
